package com.itheima.ssm.dao;

import com.itheima.ssm.domain.Member;
import com.itheima.ssm.domain.Orders;
import com.itheima.ssm.domain.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

//订单dao层
public interface IOrdersDao {
    @Select("select * from orders")
    @Results(
    {@Result(id = true, column = "id", property = "id"),
    @Result(column = "orderNum", property = "orderNum"),
    @Result(column = "orderTime", property = "orderTime"),
    @Result(column = "orderStatus", property = "orderStatus"),
    @Result(column = "peopleCount", property = "peopleCount"),
    @Result(column = "payType", property = "payType"),
    @Result(column = "orderDesc", property = "orderDesc"),
    @Result(column = "productId", property = "product", javaType = Product.class,one = @One(select = "com.itheima.ssm.dao.IProductDao.findById"))})

   public List<Orders> findAll() throws Exception;


   //多表操作
   @Select("select * from orders where id=#{ordersId}")
   @Results({
           @Result(id = true, property = "id", column = "id"),
           @Result(property = "orderNum", column = "orderNum"),
           @Result(property = "orderTime", column = "orderTime"),
           @Result(property = "orderStatus", column = "orderStatus"),
           @Result(property = "peopleCount", column = "peopleCount"),
           @Result(property = "peopleCount", column = "peopleCount"),
           @Result(property = "payType", column = "payType"),
           @Result(property = "orderDesc", column = "orderDesc"),
           @Result(property = "product", column = "productId", javaType = Product.class, one = @One(select = "com.itheima.ssm.dao.IProductDao.findById")),
           @Result(property = "member",column = "memberId",javaType = Member.class,one = @One(select = "com.itheima.ssm.dao.IMemberDao.findById")),
           @Result(property = "travellers",column = "id",javaType =java.util.List.class,many = @Many(select = "com.itheima.ssm.dao.ITravellerDao.findByOrdersId"))
   })
    public Orders findById(String orderId)throws Exception;
}












